package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 拆创建MinioClient的Bean实例，用于spring注入
 */
@Configuration
/*注册MinioProperties*/
@EnableConfigurationProperties(value = MinioProperties.class)
/*只有当配置文件中有minio.endpoint时才会生效*/
@ConditionalOnProperty(name = "minio.endpoint")
public class MinioBean {
    @Autowired
    private MinioProperties minioProperties;

    @Bean
    public MinioClient minioClient() {
        return new MinioClient.Builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
    }
}
